package com.gp.billsrecord.ui.main.adapters

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.gp.billsrecord.base.BasePagingDataAdapter
import com.gp.billsrecord.databinding.ItemBillFlowBinding
import com.gp.billsrecord.extensions.toMoney
import com.gp.billsrecord.model.data.BillFlowInfo
import com.gp.billsrecord.util.DateUtil

class BillFlowAdapter : BasePagingDataAdapter<BillFlowInfo, ItemBillFlowBinding>() {
    override fun onBind(binding: ItemBillFlowBinding, item: BillFlowInfo?) {
        item?.also {
            //备注
            if (item.mark.isNotEmpty()) {
                binding.tvFlowMark.visibility = View.VISIBLE
                binding.tvFlowMark.text = item.mark
            } else {
                binding.tvFlowMark.visibility = View.INVISIBLE
            }
            //消费类型
            binding.tvFlowType.text = item.type
            //创建时间
            binding.tvFlowDateTime.text = DateUtil.formatDateTime(item.createTime, "MM-dd HH:mm")
            //消费金额
            binding.tvFlowAmount.text =
                "${if (item.isIncome) " + " else " - "}${item.money.toMoney()}"
        }
    }

    override fun createBinding(
        inflate: LayoutInflater,
        parent: ViewGroup,
        viewType: Int
    ): ItemBillFlowBinding = ItemBillFlowBinding.inflate(inflate, parent, false)
}
